import numpy as np
import ImageModelGenerator
# 方向
directions = np.array([
    (0, 0, 1),  # 前
    (0, 0, -1),  # 后
    (-1, 0, 0),  # 左
    (1, 0, 0),  # 右
    (0, 1, 0),  # 上
    (0, -1, 0)  # 下
])

intensity = 0.7
v_ao_colors = np.array([0.6 * intensity, 0.8 * intensity, 0.85 * intensity, 1, 0.4 * intensity], dtype=np.float32)
# 立方体的角落方块位置（用于计算AO，每个点对应4个角落方块）
pads = np.array([
    # Front face
    (0, 0, 1),
    (-1, -1, 1),
    (-1, 0, 1),
    (0, -1, 1),

    (0, 0, 1),
    (1, -1, 1),
    (1, 0, 1),
    (0, -1, 1),

    (0, 0, 1),
    (1, 1, 1),
    (1, 0, 1),
    (0, 1, 1),

    (0, 0, 1),
    (-1, 1, 1),
    (0, 1, 1),
    (-1, 0, 1),

    # Back face
    (0, 0, -1),
    (1, -1, -1),
    (1, 0, -1),
    (0, -1, -1),

    (0, 0, -1),
    (-1, -1, -1),
    (-1, 0, -1),
    (0, -1, -1),

    (0, 0, -1),
    (-1, 1, -1),
    (-1, 0, -1),
    (0, 1, -1),

    (0, 0, -1),
    (1, 1, -1),
    (0, 1, -1),
    (1, 0, -1),

    # Left face
    (-1, 0, 0),
    (-1, -1, -1),
    (-1, -1, 0),
    (-1, 0, -1),

    (-1, 0, 0),
    (-1, -1, 1),
    (-1, 0, 1),
    (-1, -1, 0),

    (-1, 0, 0),
    (-1, 1, 1),
    (-1, 0, 1),
    (-1, 1, 0),

    (-1, 0, 0),
    (-1, 1, -1),
    (-1, 1, 0),
    (-1, 0, -1),

    # Right face
    (1, 0, 0),
    (1, -1, 1),
    (1, -1, 0),
    (1, 0, 1),

    (1, 0, 0),
    (1, -1, -1),
    (1, 0, -1),
    (1, -1, 0),

    (1, 0, 0),
    (1, 1, -1),
    (1, 0, -1),
    (1, 1, 0),

    (1, 0, 0),
    (1, 1, 1),
    (1, 1, 0),
    (1, 0, 1),

    # Top face
    (0, 1, 0),
    (-1, 1, 1),
    (-1, 1, 0),
    (0, 1, 1),

    (0, 1, 0),
    (1, 1, 1),
    (0, 1, 1),
    (1, 1, 0),

    (0, 1, 0),
    (1, 1, -1),
    (0, 1, -1),
    (1, 1, 0),

    (0, 1, 0),
    (-1, 1, -1),
    (0, 1, -1),
    (-1, 1, 0),

    # Bottom face
    (0, -1, 0),
    (1, -1, -1),
    (0, -1, -1),
    (1, -1, 0),

    (0, -1, 0),
    (1, -1, 1),
    (1, -1, 0),
    (0, -1, 1),

    (0, -1, 0),
    (-1, -1, 1),
    (-1, -1, 0),
    (0, -1, 1),

    (0, -1, 0),
    (-1, -1, -1),
    (0, -1, -1),
    (-1, -1, 0)

])

# 立方体的顶点数据 (pos_x, pos_y, pos_z, uv_x, uv_y, normal_x, normal_y, normal_z, aoIntensity, smoothness)
vertices = np.array([
    # Front face
    (-0.5, -0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (0.5, 0.5, 0.5, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (-0.5, 0.5, 0.5, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0),

    # Back face
    (0.5, -0.5, -0.5, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0),
    (-0.5, -0.5, -0.5, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0),
    (-0.5, 0.5, -0.5, 1.0, 1.0, 0.0, 0.0, -1.0, 0.0, 1.0),
    (0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 1.0),

    # Left face
    (-0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0),
    (-0.5, -0.5, 0.5, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0),
    (-0.5, 0.5, 0.5, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0),
    (-0.5, 0.5, -0.5, 0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0),

    # Right face
    (0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0),
    (0.5, -0.5, -0.5, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0),
    (0.5, 0.5, -0.5, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0),
    (0.5, 0.5, 0.5, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0),

    # Top face
    (-0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0),
    (0.5, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0),
    (0.5, 0.5, -0.5, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0),
    (-0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0),

    # Bottom face
    (0.5, -0.5, -0.5, 1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0),
    (0.5, -0.5, 0.5, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0),
    (-0.5, -0.5, 0.5, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0),
    (-0.5, -0.5, -0.5, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0),
], dtype=np.float32)

# 立方体的索引数据
indices = np.array([
    # Front face
    0, 1, 2, 2, 3, 0,

    # Back face
    4, 5, 6, 6, 7, 4,

    # Left face
    8, 9, 10, 10, 11, 8,

    # Right face
    12, 13, 14, 14, 15, 12,

    # Top face
    16, 17, 18, 18, 19, 16,

    # Bottom face
    20, 21, 22, 22, 23, 20,
], dtype=np.uint32)

# 植物方块的顶点数据 (pos_x, pos_y, pos_z, uv_x, uv_y, normal_x, normal_y, normal_z, aoIntensity, smoothness)
plant_vertices = np.array([
    # Front face
    (-0.5, -0.5, -0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (0.5, 0.5, 0.5, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (-0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0),

    (0.5, -0.5, -0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (-0.5, -0.5, 0.5, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (-0.5, 0.5, 0.5, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0),
    (0.5, 0.5, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0),
], dtype=np.float32)

# 植物方块的索引数据
plant_indices = np.array([
    0, 1, 2, 2, 3, 0,
    2, 1, 0, 0, 3, 2,
    4, 5, 6, 6, 7, 4,
    6, 5, 4, 4, 7, 6,
], dtype=np.uint32)

# 天空盒顶点数据
skybox_vertices = np.array([
    # Front face
    (-0.5, -0.5, 0.5, 0.0, 0.0),
    (0.5, -0.5, 0.5, 1.0, 0.0),
    (0.5, 0.5, 0.5, 1.0, 1.0),
    (-0.5, 0.5, 0.5, 0.0, 1.0),

    # Back face
    (0.5, -0.5, -0.5, 0.0, 0.0),
    (-0.5, -0.5, -0.5, 0.0, 0.0),
    (-0.5, 0.5, -0.5, 0.0, 0.0),
    (0.5, 0.5, -0.5, 0.0, 0.0),

    # Left face
    (-0.5, -0.5, -0.5, 0.0, 0.0),
    (-0.5, -0.5, 0.5, 0.0, 0.0),
    (-0.5, 0.5, 0.5, 0.0, 0.0),
    (-0.5, 0.5, -0.5, 0.0, 0.0),

    # Right face
    (0.5, -0.5, 0.5, 0.0, 0.0),
    (0.5, -0.5, -0.5, 0.0, 0.0),
    (0.5, 0.5, -0.5, 0.0, 0.0),
    (0.5, 0.5, 0.5, 0.0, 0.0),

    # Top face
    (-0.5, 0.5, 0.5, 0.0, 0.0),
    (0.5, 0.5, 0.5, 0.0, 0.0),
    (0.5, 0.5, -0.5, 0.0, 0.0),
    (-0.5, 0.5, -0.5, 0.0, 0.0),

    # Bottom face
    (0.5, -0.5, -0.5, 0.0, 0.0),
    (0.5, -0.5, 0.5, 0.0, 0.0),
    (-0.5, -0.5, 0.5, 0.0, 0.0),
    (-0.5, -0.5, -0.5, 0.0, 0.0),
], dtype=np.float32)

select_frame_size = 0.505
# 方块框选的顶点数据 (pos_x, pos_y, pos_z, uv_x, uv_y, normal_x, normal_y, normal_z, aoIntensity)
select_frame_vertices = np.array([
    # Front face
    (-select_frame_size, -select_frame_size, select_frame_size, 0.0, 0.0),
    (select_frame_size, -select_frame_size, select_frame_size, 1.0, 0.0),
    (select_frame_size, select_frame_size, select_frame_size, 1.0, 1.0),
    (-select_frame_size, select_frame_size, select_frame_size, 0.0, 1.0),

    # Back face
    (select_frame_size, -select_frame_size, -select_frame_size, 0.0, 0.0),
    (-select_frame_size, -select_frame_size, -select_frame_size, 1.0, 0.0),
    (-select_frame_size, select_frame_size, -select_frame_size, 1.0, 1.0),
    (select_frame_size, select_frame_size, -select_frame_size, 0.0, 1.0),

    # Left face
    (-select_frame_size, -select_frame_size, -select_frame_size, 0.0, 0.0),
    (-select_frame_size, -select_frame_size, select_frame_size, 1.0, 0.0),
    (-select_frame_size, select_frame_size, select_frame_size, 1.0, 1.0),
    (-select_frame_size, select_frame_size, -select_frame_size, 0.0, 1.0),

    # Right face
    (select_frame_size, -select_frame_size, select_frame_size, 0.0, 0.0),
    (select_frame_size, -select_frame_size, -select_frame_size, 1.0, 0.0),
    (select_frame_size, select_frame_size, -select_frame_size, 1.0, 1.0),
    (select_frame_size, select_frame_size, select_frame_size, 0.0, 1.0),

    # Top face
    (-select_frame_size, select_frame_size, select_frame_size, 0.0, 0.0),
    (select_frame_size, select_frame_size, select_frame_size, 1.0, 0.0),
    (select_frame_size, select_frame_size, -select_frame_size, 1.0, 1.0),
    (-select_frame_size, select_frame_size, -select_frame_size, 0.0, 1.0),

    # Bottom face
    (select_frame_size, -select_frame_size, -select_frame_size, 0.0, 0.0),
    (select_frame_size, -select_frame_size, select_frame_size, 1.0, 0.0),
    (-select_frame_size, -select_frame_size, select_frame_size, 1.0, 1.0),
    (-select_frame_size, -select_frame_size, -select_frame_size, 0.0, 1.0),
], dtype=np.float32)

# 索引数据
skybox_indices = np.array([
    # Front face
    2, 1, 0, 0, 3, 2,

    # Back face
    6, 5, 4, 4, 7, 6,

    # Left face
    10, 9, 8, 8, 11, 10,

    # Right face
    14, 13, 12, 12, 15, 14,

    # Top face
    18, 17, 16, 16, 19, 18,

    # Bottom face
    22, 21, 20, 20, 23, 22,
], dtype=np.uint32)

# clouds_vertices, clouds_indices = ImageModelGenerator.generate_model("Resources/Clouds/clouds.png")
#clouds_layout = np.zeros((256, 256))
clouds_layout = ImageModelGenerator.CLOUDS_LAYOUT

cloud_use_face_vertices = np.array([
    # Front face
    (-0.5, -0.5, 0.5, 0.0, 0.0, 1.0),
    (0.5, -0.5, 0.5, 0.0, 0.0, 1.0),
    (0.5, 0.5, 0.5, 0.0, 0.0, 1.0),
    (-0.5, 0.5, 0.5, 0.0, 0.0, 1.0),

    # Back face
    (0.5, -0.5, -0.5, 0.0, 0.0, -1.0),
    (-0.5, -0.5, -0.5, 0.0, 0.0, -1.0),
    (-0.5, 0.5, -0.5, 0.0, 0.0, -1.0),
    (0.5, 0.5, -0.5, 0.0, 0.0, -1.0),

    # Left face
    (-0.5, -0.5, -0.5, -1.0, 0.0, 0.0),
    (-0.5, -0.5, 0.5, -1.0, 0.0, 0.0),
    (-0.5, 0.5, 0.5, -1.0, 0.0, 0.0),
    (-0.5, 0.5, -0.5, -1.0, 0.0, 0.0),

    # Right face
    (0.5, -0.5, 0.5, 1.0, 0.0, 0.0),
    (0.5, -0.5, -0.5, 1.0, 0.0, 0.0),
    (0.5, 0.5, -0.5, 1.0, 0.0, 0.0),
    (0.5, 0.5, 0.5, 1.0, 0.0, 0.0),

    # Top face
    (-0.5, 0.5, 0.5, 0.0, 1.0, 0.0),
    (0.5, 0.5, 0.5, 0.0, 1.0, 0.0),
    (0.5, 0.5, -0.5, 0.0, 1.0, 0.0),
    (-0.5, 0.5, -0.5, 0.0, 1.0, 0.0),

    # Bottom face
    (0.5, -0.5, -0.5, 0.0, -1.0, 0.0),
    (0.5, -0.5, 0.5, 0.0, -1.0, 0.0),
    (-0.5, -0.5, 0.5, 0.0, -1.0, 0.0),
    (-0.5, -0.5, -0.5, 0.0, -1.0, 0.0),
], dtype=np.float32)
# # 云层顶点数据
# clouds_vertices = np.array([
#     # Bottom face
#     (800, 0, -800, 0.3, 0.3),
#     (800, 0, 800, 0.3, 0.0),
#     (-800, 0, 800, 0.0, 0.0),
#     (-800, 0, -800, 0.0, 0.3),
# ], dtype=np.float32)
#
# # 云层索引数据
# clouds_indices = np.array([
#     0, 1, 2, 2, 3, 0,
#     2, 1, 0, 0, 3, 2
# ], dtype=np.uint32)

# UI顶点数据
ui_vertices = np.array([
    -0.5, -0.5, 0.0, 0.0, 0.0,
    0.5, -0.5, 0.0, 1.0, 0.0,
    0.5, 0.5, 0.0, 1.0, 1.0,
    -0.5, 0.5, 0.0, 0.0, 1.0
], dtype=np.float32)

# UI索引数据
ui_indices = np.array([
    0, 1, 2, 2, 3, 0
], dtype=np.uint32)

with open('Resources/Shaders/opaque/vertex.vert', 'r', encoding='utf-8') as file:
    vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/opaque/fragment.frag', 'r', encoding='utf-8') as file:
    fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/skybox/skybox.vert', 'r', encoding='utf-8') as file:
    skybox_vert_shader = file.read()
    file.close()
with open('Resources/Shaders/skybox/skybox.frag', 'r', encoding='utf-8') as file:
    skybox_frag_shader = file.read()
    file.close()

with open('Resources/Shaders/skybox_main_menu/skybox_main_menu.vert', 'r', encoding='utf-8') as file:
    skybox_main_menu_vert_shader = file.read()
    file.close()
with open('Resources/Shaders/skybox_main_menu/skybox_main_menu.frag', 'r', encoding='utf-8') as file:
    skybox_main_menu_frag_shader = file.read()
    file.close()

with open('Resources/Shaders/clouds/clouds_vertex_shader.vert', 'r', encoding='utf-8') as file:
    clouds_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/clouds/clouds_frag_shader.frag', 'r', encoding='utf-8') as file:
    clouds_fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/select_frame/select_frame_shader.vert', 'r', encoding='utf-8') as file:
    select_frame_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/select_frame/select_frame_shader.frag', 'r', encoding='utf-8') as file:
    select_frame_fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/shadow/shadow_vertex_shader.vert', 'r', encoding='utf-8') as file:
    shadow_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/shadow/shadow_fragment_shader.frag', 'r', encoding='utf-8') as file:
    shadow_fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/ui/ui_vertex_shader.vert', 'r', encoding='utf-8') as file:
    ui_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/ui/ui_fragment_shader.frag', 'r', encoding='utf-8') as file:
    ui_fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/ui/text_vertex_shader.vert', 'r', encoding='utf-8') as file:
    text_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/ui/text_fragment_shader.frag', 'r', encoding='utf-8') as file:
    text_fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/particle/particle_vertex_shader.vert', 'r', encoding='utf-8') as file:
    particle_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/particle/particle_fragment_shader.frag', 'r', encoding='utf-8') as file:
    particle_fragment_shader = file.read()
    file.close()

with open('Resources/Shaders/ui_three/ui_three_vertex_shader.vert', 'r', encoding='utf-8') as file:
    ui_three_vertex_shader = file.read()
    file.close()
with open('Resources/Shaders/ui_three/ui_three_fragment_shader.frag', 'r', encoding='utf-8') as file:
    ui_three_fragment_shader = file.read()
    file.close()
